package com.example.demo.config.token;

import java.util.Collection;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;

import lombok.Data;

/**
 * 登录用户信息，User是security的一个子类，用于复写user信息
 * <p>
 * 这个的具体用处是这样的：
 * login后存储的是自己定义的Users，而SecurityContextHolder.getContext().getAuthentication().getPrincipal();取出的是UserDetails对象，
 * 就可以用这个user对象进行自动get/set到这个token对象里
 */
@Data
public class UserToken extends User {

	private Integer id;
	private String username;
	private String password;
	private String role;

	public UserToken() {
		super(null, null, null);
	}

	public UserToken(String username, String password, Collection<? extends GrantedAuthority> authorities) {
		super(username, password, authorities);
	}

	public UserToken(String username, String password, boolean enabled, boolean accountNonExpired,
			boolean credentialsNonExpired, boolean accountNonLocked,
			Collection<? extends GrantedAuthority> authorities) {
		super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
	}
}
